const mongoose = require('mongoose');
var express = require('express')
var kemu = express()

const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const {kemuService } = require('../../service/impl/kemuService/index');


kemu.post('/post/kemu/add', async (req,res) => {
  let result
  try {
    let news  = req.body.news
    result =  await kemuService.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  kemu.post('/post/kemu/delete', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      result =  await kemuService.getIns().findByIdAndDelete(id)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  kemu.post('/post/kemu/update', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      let updates = req.body.updates
      result =  await kemuService.getIns().findByIdAndUpdate(id,updates)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  kemu.post('/post/kemu/query', async (req,res) => {
    let result
    let fills= ['xueke_id']
    try {
      result =  await kemuService.getIns().find(null,null,fills)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })


    // // 根据学科id查找包含的科目
  kemu.post('/post/kemu/queryKemuByXuekeId',async (req,res) => {
    let result

    let fills= ['xueke_id']
    try {
      let conditions  = {

        'xueke_id' : req.body.conditions.xueke_id
      }
      result =  await kemuService.getIns().find(conditions,null,fills)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })




  
  module.exports= kemu


  // router.post('/post/kemu/add',(req,res) => {
  //   controller.kemuController.getSigleIns().create(req,res)
  // })
  
  // router.post('/post/kemu/delete',(req,res) => {
  //   controller.kemuController.getSigleIns().findByIdAndRemove(req,res)
  // })
  
  // router.post('/post/kemu/update',(req,res) => {
  //   controller.kemuController.getSigleIns().findByIdAndUpdate(req,res)
  // })
  
  // router.post('/post/kemu/querykemuPages',(req,res) => {
  //   controller.kemuController.getSigleIns().queryAll(req,res)
  // })
  
  // // 根据科目id查找包含的知识点
  // router.post('/post/kemu/findIncludePointsByKemuid',(req,res) => {
  //   controller.kemuController.getSigleIns().findPointByKemuId(req,res)
  // })
  

  